package com.CoreryBlack.controller;

import com.CoreryBlack.po.PageBean;
import com.CoreryBlack.po.Result;
import com.CoreryBlack.po.Student;
import com.CoreryBlack.po.StudentQueryParam;
import com.CoreryBlack.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description StudentController
 * @Author CoreryBlack
 * @Date 2024-09-19
 */

@Slf4j
@RestController
@RequestMapping("/students")
public class StudentController {

    @Autowired
    private StudentService studentService;

    @GetMapping
    public Result list(StudentQueryParam studentQueryParam){
        PageBean pageBean = studentService.list(studentQueryParam);
        return Result.success(pageBean);
    }

    @DeleteMapping("/{ids}")
    public Result deleteByIds(@PathVariable List<Integer> ids){
        log.info("批量删除班级：ids={}",ids);
        studentService.deleteByIds(ids);
        return Result.success();
    }

    @PostMapping
    public Result saveStudent(@RequestBody Student student){
        studentService.saveStudent(student);
        return Result.success();
    }

    @GetMapping("/students/query/{id}")
    public Result queryById(Integer id){
        Student student = studentService.queryById(id);
        return Result.success(student);
    }

    @PutMapping
    public Result updateStudent(@RequestBody Student student){
        studentService.updateStudent(student);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getInfo(@PathVariable Integer id){
        Student student = studentService.getInfo(id);
        return Result.success(student);
    }

    @PutMapping("/violation/{id}/{score}")
    public Result updateStudent(@PathVariable Integer id,@PathVariable Integer score){
        studentService.updateStudentScore(id,score);
        return Result.success();
    }

}
